﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using OnlineCourse.JWTAuthorizePolicy;
using OnlineCourse.Model;
using OnlineCourse.Model.Entity;
using OnlineCourse.Services.Model;

namespace OnlineCourse.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CourseController : ControllerBase
    {
        private readonly PermissionRequirement _requirement;
        private readonly Services.CourseService _usbll;
        public CourseController(ApplicationDbContext db, PermissionRequirement requirement)
        {

            _requirement = requirement;
            _usbll = new Services.CourseService(db);
        }
        /// <summary>
        /// 添加课程相关信息
        /// </summary>
        /// <param name="teacherId"></param>
        /// <param name="title"></param>
        /// <param name="type"></param>
        /// <param name="imagePath"></param>
        /// <param name="detailed"></param>
        /// <param name="price"></param>
        /// <param name="buyNum"></param>
        /// <param name="lessonHour"></param>
        /// <returns></returns>
        [HttpPost("Add")]
        public IActionResult Add(Guid teacherId,string title, int type, string imagePath, string detailed, decimal price, string lessonHour)
        {
            bool mark = _usbll.Add(teacherId,title, type, imagePath, detailed, price, lessonHour);

            return Ok(mark);
        }
        /// <summary>
        /// 课程信息更新
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        /// <param name="type"></param>
        /// <param name="imagePath"></param>
        /// <param name="detailed"></param>
        /// <param name="price"></param>
        /// <param name="buyNum"></param>
        /// <param name="lessonHour"></param>
        /// <returns></returns>
        [HttpPut("Update")]
        public IActionResult Update(Guid id, string title, int type, string imagePath, string detailed, decimal price,string lessonHour)
        {
            bool mark = _usbll.Update(id, title, type, imagePath, detailed, price, lessonHour);
            return Ok(mark);
        }
        /// <summary>
        /// 删除课程信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("Delete")]
        public IActionResult Delete(Guid id)
        {
            bool mark = _usbll.Delete(id);
            return Ok(mark);
        }
        /// <summary>
        /// 单门课程详细内容查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet ("GetCourse")]
        public IActionResult GetCourse(Guid id)
        {
            var mark = _usbll.GetCourse(id);
            return Ok(mark);
        }
        /// <summary>
        /// 按课程类型分页查询
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet ("GetCourseList")]
        public async Task<IActionResult> GetCourseList(int Type, int page , int pageSize)
        {
            //IList<CourseModel> list = new List<CourseModel>();
            //await Task.Run(() => { list = _usbll.GetCourseList(Type , out total, page , pageSize ); });
            //return Ok(new {total=total ,data=list});
            int total = 0;
            var mark = _usbll.GetCourseList(Type, out total, page , pageSize);
            return Ok(new { total = total, data = mark });
        }
        /// <summary>
        /// 无条件查询按老师排序
        /// </summary>
        /// <returns></returns>
       [HttpGet ("GetList")]
       public IActionResult GetList()
        {
            var mark = _usbll.GetList();
            return Ok(mark);
        }
    }
}